<?php
$host = "localhost"; // Host name 
$username = "root"; // Mysql username 
$password = "babu9231"; // Mysql password 
$db_name = "bullying"; // Database name 
$tbl_name = "accounts"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("Cannot Connect"); 
mysql_select_db("$db_name")or die("Cannot Select DB");

// username and password sent from form 
$usernamebo = $_POST['user']; 
$passwordbo = $_POST['pass'];

// To protect MySQL injection (more detail about MySQL injection)
$usernamebo = stripslashes($usernamebo);
$passwordbo = stripslashes($passwordbo);
$usernamebo = mysql_real_escape_string($usernamebo);
$passwordbo = mysql_real_escape_string($passwordbo);

$sql="SELECT * FROM $tbl_name WHERE username= '$usernamebo' AND password= '$passwordbo'";
$result = mysql_query($sql);
// Mysql_num_row is counting table row
$count = mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("usernamebo");
session_register("passwordbo"); 
setcookie ("usernamebo", $usernamebo); //grava o cookie com o login
setcookie ("passwordbo", $passwordbo); //grava o cookie com a senha
header("location:home.php");
}
else {
echo '
<link rel="stylesheet" type="text/css" href="style.css"/>
<div id="main">
	<div id="header">
		<ul class="nav">
			<a href="index.php"><li>Home</li></a>
	   		<a href="about.php"><li>About</li></a>
	   		<a href="cadastro.php"><li>Join Now</li></a>
			<a href="#"><li>Forums</li></a>
	   		<a href="#"><li>Support</li></a>
		</ul>
	</div>   	
	
	<div id="logo"> 
  	</div>	
  	
	<div id="leftMenu">
	<form action= "login_.php" target="_self" method="post" name="login" id="login"></a> 
		<label for="user">Username:</label>
        	<input type="text" name="user" id="user" />
        <label for="pass">Password:</label>
        	<input type="password" name="pass" id="pass" />
	<input type="submit" name="submit" value="Login" style="cursor: pointer;" /> 
	</form>
    </div>    
    
	<div id="content">
      <p>Wrong Username or Password</p>
	</div>
    
	<div class="clear"></div>
	</div>
	';
}
?>